<?php

/**
 * This is the model class for table "social_history".
 *
 * The followings are the available columns in table 'social_history':
 * @property integer $id
 * @property string $drive
 * @property string $tobacco
 * @property string $illegal_drug
 * @property string $tobacco_type
 * @property string $tobacco_ammount
 * @property string $tobacco_long
 * @property string $drug_type
 * @property string $drug_ammount
 * @property string $drug_long
 * @property string $gonorrhea
 * @property string $hepatitis
 * @property string $syphills
 * @property string $hiv
 * @property integer $personalinfo_id
 *
 * The followings are the available model relations:
 * @property PersonalInformation $personalinfo
 */
class SocialHistory extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return SocialHistory the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'social_history';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('personalinfo_id', 'required'),
			array('personalinfo_id', 'numerical', 'integerOnly'=>true),
			array('drive, tobacco, illegal_drug, gonorrhea, hepatitis, syphills, hiv', 'length', 'max'=>5),
			array('tobacco_type, drug_type', 'length', 'max'=>300),
			array('tobacco_ammount, tobacco_long, drug_ammount, drug_long', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, drive, tobacco, illegal_drug, tobacco_type, tobacco_ammount, tobacco_long, drug_type, drug_ammount, drug_long, gonorrhea, hepatitis, syphills, hiv, personalinfo_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'personalinfo' => array(self::BELONGS_TO, 'PersonalInformation', 'personalinfo_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'drive' => 'Drive',
			'tobacco' => 'Tobacco',
			'illegal_drug' => 'Illegal Drug',
			'tobacco_type' => 'Tobacco Type',
			'tobacco_ammount' => 'Tobacco Ammount',
			'tobacco_long' => 'Tobacco Long',
			'drug_type' => 'Drug Type',
			'drug_ammount' => 'Drug Ammount',
			'drug_long' => 'Drug Long',
			'gonorrhea' => 'Gonorrhea',
			'hepatitis' => 'Hepatitis',
			'syphills' => 'Syphills',
			'hiv' => 'Hiv',
			'personalinfo_id' => 'Personalinfo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('drive',$this->drive,true);
		$criteria->compare('tobacco',$this->tobacco,true);
		$criteria->compare('illegal_drug',$this->illegal_drug,true);
		$criteria->compare('tobacco_type',$this->tobacco_type,true);
		$criteria->compare('tobacco_ammount',$this->tobacco_ammount,true);
		$criteria->compare('tobacco_long',$this->tobacco_long,true);
		$criteria->compare('drug_type',$this->drug_type,true);
		$criteria->compare('drug_ammount',$this->drug_ammount,true);
		$criteria->compare('drug_long',$this->drug_long,true);
		$criteria->compare('gonorrhea',$this->gonorrhea,true);
		$criteria->compare('hepatitis',$this->hepatitis,true);
		$criteria->compare('syphills',$this->syphills,true);
		$criteria->compare('hiv',$this->hiv,true);
		$criteria->compare('personalinfo_id',$this->personalinfo_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}